package dao;

import java.sql.SQLException;
import java.util.List;
import java.util.Scanner;

public class TestFind {
    public static void main(String[] args) {
        System.out.println("欢迎使用管理系统");
        System.out.println("1.查询所有学生");
        System.out.println("2.根据姓名查询学生");
        System.out.println("3.查询同一系的学生");
        //System.out.println("4.根据姓名查询学生");
        System.out.println("请输入对应的数字编号:");
        Scanner sc =new Scanner(System.in);
        int num=sc.nextInt();
        EmpDAO dao =new EmpDAO();
        switch (num){
            case 1:
                try{
                    List<Emp> list = dao.findAll();
                    for (int i = 0; i <list.size() ; i++) {
                        System.out.println(list.get(i).getName()+"----"+list.get(i).getDeptId());
                    }
                }catch (ClassCastException | SQLException e) {
                    e.printStackTrace();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
                break;
            case 2:
                System.out.println("请输入员工的姓名:");
                String name =sc.next();
                try{
                    Emp emp =dao.findByName(name);
                    if (emp!=null){
                        System.out.println(emp.getName()+"----"+emp.getDeptId());
                    }
                }catch (ClassCastException | SQLException e) {
                    e.printStackTrace();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
                break;
            case 3:
                System.out.println("请输入员工的系号:");
                int deptId =sc.nextInt();
                try{
                    List<Emp> list = dao.findByDepId(deptId);
                    for (int i = 0; i <list.size() ; i++) {
                        System.out.println(list.get(i).getName()+"----"+list.get(i).getDeptId());
                    }
                }catch (ClassCastException | SQLException e) {
                    e.printStackTrace();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
                break;

        }

    }
}
